static gboolean
parse_rev_file (OstreeRepo *self,
- const char *path,
+ GFile *f,
char **sha256,
GError **error) G_GNUC_UNUSED;
static gboolean
parse_rev_file (OstreeRepo *self,
- const char *path,
+ GFile *f,
char **sha256,
GError **error)
{
gboolean ret = FALSE;
char *rev = NULL;
- rev = ot_util_get_file_contents_utf8 (path, &temp_error);
+ if (!ot_gfile_load_contents_utf8 (f, &rev, NULL, NULL, &temp_error))
+ goto out;
+
if (rev == NULL)
{
if (g_error_matches (temp_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
if (g_str_has_prefix (rev, "ref: "))
{
GFile *ref;
- const char *ref_path;
char *ref_sha256;
gboolean subret;
ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5);
- ref_path = ot_gfile_get_path_cached (ref);
-
- subret = parse_rev_file (self, ref_path, &ref_sha256, error);
+ subret = parse_rev_file (self, ref, &ref_sha256, error);
g_clear_object (&ref);
if (!subret)
child_path = ot_gfile_get_path_cached (child);
}
- if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error))
+ if (!ot_gfile_load_contents_utf8 (child, &ret_rev, NULL, NULL, &temp_error))
{
if (allow_noent && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
OstreeObjectType type,
GError **error)
{
+ GFile *f = NULL;
char *checksum_dir = NULL;
char *object_path = NULL;
object_path = ostree_repo_get_object_path (self, checksum, type);
checksum_dir = g_path_get_dirname (object_path);
+ f = ot_gfile_new_for_path (checksum_dir);
- if (!ot_util_ensure_directory (checksum_dir, FALSE, error))
+ if (!ot_gfile_ensure_directory (f, FALSE, error))
goto out;
out:
+ g_clear_object (&f);
g_free (checksum_dir);
return object_path;
}
{
dir = g_file_get_child (priv->remote_heads_dir, remote);
- if (!ot_util_ensure_directory (ot_gfile_get_path_cached (dir), FALSE, error))
+ if (!ot_gfile_ensure_directory (dir, FALSE, error))
goto out;
}
#include "otutil.h"
gboolean
-ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error)
+ot_gfile_ensure_directory (GFile *dir,
+ gboolean with_parents,
+ GError **error)
{
- GFile *dir;
GError *temp_error = NULL;
gboolean ret = FALSE;
- dir = ot_gfile_new_for_path (path);
if (with_parents)
ret = g_file_make_directory_with_parents (dir, NULL, &temp_error);
else
ret = TRUE;
out:
- g_clear_object (&dir);
- return ret;
-}
-
-
-char *
-ot_util_get_file_contents_utf8 (const char *path,
- GError **error)
-{
- GFile *file = NULL;
- char *ret = NULL;
-
- file = ot_gfile_new_for_path (path);
- if (!ot_util_gfile_load_contents_utf8 (file, NULL, &ret, NULL, error))
- goto out;
-
- out:
- g_clear_object (&file);
return ret;
}
gboolean
-ot_util_gfile_load_contents_utf8 (GFile *file,
- GCancellable *cancellable,
- char **contents_out,
- char **etag_out,
- GError **error)
+ot_gfile_load_contents_utf8 (GFile *file,
+ char **contents_out,
+ char **etag_out,
+ GCancellable *cancellable,
+ GError **error)
{
char *ret_contents = NULL;
char *ret_etag = NULL;
return ret;
}
-GInputStream *
-ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error)
-{
- GInputStream *ret = NULL;
- int fd;
- int flags = O_RDONLY;
- const char *path = NULL;
-
- path = ot_gfile_get_path_cached (file);
-#ifdef O_NOATIME
- flags |= O_NOATIME;
-#endif
- fd = open (path, flags);
- if (fd < 0)
- {
- ot_util_set_error_from_errno (error, errno);
- goto out;
- }
-
- ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE);
-
- out:
- return ret;
-}
-
/* Like g_file_new_for_path, but only do local stuff, not GVFS */
GFile *
ot_gfile_new_for_path (const char *path)
const char *ot_gfile_get_basename_cached (GFile *file);
-gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error);
+gboolean ot_gfile_ensure_directory (GFile *dir, gboolean with_parents, GError **error);
-char * ot_util_get_file_contents_utf8 (const char *path, GError **error);
-
-gboolean ot_util_gfile_load_contents_utf8 (GFile *file,
- GCancellable *cancellable,
- char **contents_out,
- char **etag_out,
- GError **error);
-
-GInputStream *ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **error);
+gboolean ot_gfile_load_contents_utf8 (GFile *file,
+ char **contents_out,
+ char **etag_out,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
char *baseurl = NULL;
char *refpath = NULL;
char *temppath = NULL;
+ GFile *tempf = NULL;
char *remote_ref = NULL;
char *original_rev = NULL;
GKeyFile *config = NULL;
NULL);
if (!fetch_uri (repo, soup, target_uri, &temppath, error))
goto out;
+ tempf = ot_gfile_new_for_path (temppath);
- rev = ot_util_get_file_contents_utf8 (temppath, error);
- if (!rev)
+ if (!ot_gfile_load_contents_utf8 (tempf, &rev, NULL, NULL, error))
goto out;
g_strchomp (rev);